package com.weibopay.gf.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.crypto.SecureUtil;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 公共工具
 */
public class CommonUtils {
    /**
     * 无需加签参数
     */
    public static final List<String> BASIC_PARAM = Arrays.asList("sign", "sign_type");

    /**
     * 获取文件摘要
     */
    public static String fileDigest(byte[] fileBytes) {
        if (Objects.isNull(fileBytes) || fileBytes.length < 1) {
            throw new IllegalArgumentException("param is null");
        }
        return SecureUtil.md5().digestHex(fileBytes);
    }

    /**
     * 过滤无需加签参数
     */
    public static void filter(Map<String, Object> filterMap) {
        if (CollectionUtil.isEmpty(filterMap)) {
            return;
        }
        BASIC_PARAM.forEach(filterMap::remove);
    }

}
